package com.bdjk.bdmw.InfoGath.communication.protocol.beianbei;

import com.bdjk.bdmw.InfoGath.business.beianbei.vo.BeiAnBeiShortVO;
import com.bdjk.bdmw.InfoGath.communication.protocol.BaseProtocol;
import java.io.PrintStream;

public class BeiAnBeiLinkProtocol
  extends BaseProtocol<BeiAnBeiShortVO>
{
  public BeiAnBeiLinkProtocol()
  {
    this.isResponse = true;
    this.isSave = false;
  }
  
  public String encodeMessage(BeiAnBeiShortVO vo)
  {
    StringBuffer msgBuffer = new StringBuffer("[");
    msgBuffer.append(vo.getCommType()).append("*").append(vo.getTerIdent());
    String strprefix = msgBuffer.toString();
    StringBuffer link = new StringBuffer(strprefix).append("*0002*LK]");
    String monitor = strprefix + "*0007*MONITOR]";
    String center = strprefix + "*0012*CENTER,15101618651]";
    String sos = strprefix + "*0010*SOS1,15101618651]";
    String sosAll = strprefix + "*0027*SOS,13109577968,13109577968,13109577968]";
    String whiteList = strprefix + "*0016*WHITELIST1,13089213006]";
    String smsShutdown = strprefix + "*000A*SMSONOFF,0]";
    String off = strprefix + "*0008*POWEROFF]";
    String rset = strprefix + "*0005*RESET]";
    this.monitor = monitor;
    this.centerNumber = center;
    this.sos = sos;
    this.sosAll = sosAll;
    this.whiteList = whiteList;
    this.smsShutdown = smsShutdown;
    this.off = off;
    this.reset = rset;
    return link.toString();
  }
  
  public BeiAnBeiShortVO decodeMessage(String message)
  {
    BeiAnBeiShortVO vo = new BeiAnBeiShortVO();
    String[] params = message.split(",");
    if (params.length < 0) {
      return null;
    }
    System.out.println(message);
    String[] terparams = params[0].split("\\*");
    System.out.println(terparams.length);
    vo.setCommType(terparams[0]);
    vo.setTerIdent(terparams[1]);
    vo.setMsgLength(terparams[2]);
    vo.setProCode(terparams[3]);
    if (params.length > 1)
    {
      vo.setStepNum(params[1]);
      vo.setRollNum(params[2]);
      vo.setElectricity(params[3]);
    }
    this.terIdent = vo.getTerIdent();
    return vo;
  }
}
